<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增用户</title>
</head>
  <body>
  <script type="text/javascript">
  		var winUserAdd = new Windows("user_add");
  		var winRoleList = new Windows("user_role_list");
  		var winUnitList = new Windows("user_unit");
  		$(function(){
  			winUserAdd.find('#userForm').form({   
			    url:'$!basePath/admin/user/doAdd',   
			    onSubmit: function(){
			    	var pass = winUserAdd.find('#userForm').form("validate");
			    	if(pass){
			    		winUserAdd.find("#ok").linkbutton("disable");
			    	}
			    	return pass; 
			    },   
			    success:function(data){
			   		var result = jQuery.parseJSON(data);   
			        if(result.isSaved){
			        	top.Notiy.success("添加成功!");
		        		winUserAdd.setReturnValue(true);
						winUserAdd.close();
			        }else{
			        	top.Dialog.alert("错误",result.error,"error");
			        }
			        winUserAdd.find("#ok").linkbutton("enable");
			    }
			}); 
			initWindows();
			initToolbar();//初始化按钮
  		});
  		function initWindows(){
  			winRoleList.windows({
  				title:"选择角色",
				width:450,
				height:350,
				modal:true,
				cache:false,
				closed:true,
				iconCls:'icon-user-add',
				href:"$!basePath/admin/user/role",
				onClose:function(){
					var returnValue = winRoleList.getReturnValue();
					if(returnValue!="false"){
						returnValue = JSONObject.parseJSON(returnValue);
						winUserAdd.find("#userRoles").val(returnValue.ids);
						winUserAdd.find("#userRoles_Tip").text("已选择:"+returnValue.names);
						winUserAdd.find("#userRoles_Tip").css("fontWeight","bold");
					}else{
						winUserAdd.find("#userRoles").val("");
						winUserAdd.find("#userRoles_Tip").text("默认为$!defaultRole");
						winUserAdd.find("#userRoles_Tip").css("fontWeight","normal");
					}
				}
  			});
  			winUnitList.windows({
  				title:"选择机构",
				width:250,
				height:350,
				modal:true,
				cache:false,
				closed:true,
				iconCls:'icon-unit-add',
				href:"$!basePath/admin/user/unit",
				onClose:function(){
					var returnValue = winUnitList.getReturnValue();
					if(returnValue != "default" && returnValue!="false"){//判断是否使用的默认机构
						var selectUnit = JSONObject.parseJSON(returnValue);
						winUserAdd.find("#userUnits").val(selectUnit.id);
						winUserAdd.find("#userUnits_Tip").text("已选择:["+selectUnit.name+"]");
						winUserAdd.find("#userUnits_Tip").css("fontWeight","bold");
					}else if(returnValue!="false"){
						winUserAdd.find("#userUnits").val("");
						winUserAdd.find("#userUnits_Tip").text("默认为$!defaultUnit");
						winUserAdd.find("#userUnits_Tip").css("fontWeight","normal");
					}
				}
  			});
  		}
  		function initToolbar(){
  			winUserAdd.find("#btnRoleList").click(function(){
  				var selectRoles = winUserAdd.find("#userRoles").val();
  				if(selectRoles){
  					winRoleList.setParam(selectRoles);
  				}
  				winRoleList.windows("open");
  			});
  			winUserAdd.find("#btnUnitList").click(function(){
  				var selectUnits = winUserAdd.find("#userUnits").val();
  				if(selectUnits){
  					winUnitList.setParam(selectUnits);
  				}
  				winUnitList.open();
  			});
  		}
  		function useradd_ok(){
  			winUserAdd.find('#userForm').submit();
  			//winUserAdd.windows("shake");
  		}
  		function useradd_cancel(){
  			winUserAdd.windows('close');
  		}
	</script>
    <div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center',border:false" style="background:#fff;">
				<form id="userForm" method="post" style="padding-top:10px;padding-left:20px;">
					<table width="90%">
						<tr>
							<td>登录名：</td>
							<td>
							<input class="easyui-validatebox" type="text" name="loginName" maxlength="20" data-options="required:true,validType:'minLength[6]'" />  
							</td>
							<td>
								姓名：
							</td>
							<td>
								<input class="easyui-validatebox" type="text" name="realName" maxlength="20" data-options="required:true,validType:'minLength[2]'" />  
							</td>
						</tr>
						<tr>
							<td>密码：</td>
							<td>
							<input id="pwd" class="easyui-validatebox" type="password" name="passWord" maxlength="20" data-options="required:true,validType:'minLength[6]'" />  
							</td>
							<td>
								确认密码：
							</td>
							<td>
								<input id="rpwd" class="easyui-validatebox" type="password" name="rPassWord" maxlength="20" required="true" validType="equals['#pwd']" />  
							</td>
						</tr>
						<tr>
							<td>固定电话：</td>
							<td>
							<input class="easyui-validatebox" name="telphone" maxlength="20" data-options="validType:'telphone'" />  
							</td>
							<td>
								手机：
							</td>
							<td>
								<input class="easyui-validatebox" name="mobile" maxlength="20" data-options="validType:'mobile'"/>  
							</td>
						</tr>
						<tr>
							<td>Email：</td>
							<td>
							<input class="easyui-validatebox" name="eMail" maxlength="50" data-options="validType:'email'" />  
							</td>
							<td>
								QQ：
							</td>
							<td>
								<input class="easyui-validatebox" name="qQ" maxlength="12"/>  
							</td>
						</tr>
						<tr>
							<td>个人主页：</td>
							<td colspan="3">
								<input class="easyui-validatebox" name="web" maxlength="50" data-options="validType:'url'" style="width:80%;"/>  
							</td>
						</tr>
						<tr>
							<td>地址：</td>
							<td colspan="3">
								<textarea class="easyui-textarea" name="address" rows="3" style="width:80%;"></textarea>  
							</td>
						</tr>
						<tr>
							<td>是否启用：</td>
							<td colspan="3">
								<label>启用</label>
								<input type="radio" name="enabled" value="0" checked="checked"/>
								<label>不启用</label>
								<input type="radio" name="enabled" value="1"/>
							</td>
						</tr>
						<tr>
							<td>页面风格：</td>
							<td colspan="3">
								<select class="easyui-combobox" name="pageStyle" data-options="editable:false">
									<option value="default" selected="selected">默认</option>
								</select>
							</td>
						</tr>
						<tr>
							<td>角色列表：</td>
							<td colspan="3">
								<input type="hidden" id="userRoles" name="userRoles"/>
								<a id="btnRoleList" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-role-add'">选择</a> 
								<span id="userRoles_Tip">默认为$!defaultRole</span>
							</td>
						</tr>
						<tr>
							<td>机构列表：</td>
							<td colspan="3">
								<input type="hidden" id="userUnits" name="userUnits"/>
								<a id="btnUnitList" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-unit-add'">选择</a>
								<span id="userUnits_Tip">默认为$!defaultUnit</span>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:center;padding:5px 0;">
				<a id="ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="useradd_ok()">确定</a>
				<a id="cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="useradd_cancel()">取消</a>
			</div>
		</div>
  </body>
</html>
